#include "ListComp.h"
#include "IVisitor.h"

ListComp::ListComp(const exprTypePtr& elt, const ComprehensionTypeList& generators, int ctx, int nodeId):
    exprType(nodeId),
    _elt(elt),
    _generators(generators),
    _ctx(ctx)
{
}
    
ListComp::~ListComp()
{
    _generators.clear();
}
    
QString ListComp::type() const
{
    return "ListComp";
}
    

exprTypePtr ListComp::elt()
{
    return _elt;
}

void ListComp::setElt(const exprTypePtr& elt)
{
    _elt = elt;
}

ComprehensionTypeList ListComp::generators()
{
    return _generators;
}

void ListComp::setGenerators(const ComprehensionTypeList& generators)
{
    _generators = generators;
}

int ListComp::ctx()
{
    return _ctx;
}

void ListComp::setCtx(int ctx)
{
    _ctx = ctx;
}

    
QString ListComp::toString() const
{
    return QString("ListComp[elt=%1, generators=%2, ctx=%3]").
                arg(_elt ? _elt->toString():"").
                arg(_generators.toString()).
                arg(_ctx);
}
    
void ListComp::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitListComp(node.dynamicCast<ListComp>());
}
    
void ListComp::traverse(IVisitor* visitor)
{
    if (_elt != NULL)
        _elt->accept(visitor, _elt);
    _generators.traverse(visitor);
}